package com.macro.mall.tiny.service.Impl;

import cn.hutool.core.util.StrUtil;
import com.github.pagehelper.PageHelper;
import com.macro.mall.tiny.mbg.mapper.PmsBrandMapper;
import com.macro.mall.tiny.mbg.model.PmsBrand;
import com.macro.mall.tiny.mbg.model.PmsBrandExample;
import com.macro.mall.tiny.service.PmsBrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PmsBrandServiceImpl implements PmsBrandService {


    @Autowired
    private PmsBrandMapper  pmsBrandMapper;

    //获取全部品牌列表
//    @Override
    public List<PmsBrand> getList() {

        return pmsBrandMapper.selectByExample(new PmsBrandExample());
    }


    public int add(PmsBrand pmsBrand){
        int code=pmsBrandMapper.insertSelective(pmsBrand);
        return code;
    }

    //更新指定品牌
    public int updateById(Long id,PmsBrand pmsBrand){
        PmsBrandExample example=new PmsBrandExample();
        PmsBrandExample.Criteria criteria= example.createCriteria();
        criteria.andIdEqualTo(id);


        int code=pmsBrandMapper.updateByExampleSelective(pmsBrand,example);
        return code;
    }

    //根据id删除指定品牌
    public int deleteById(Long id){
        int code=pmsBrandMapper.deleteByPrimaryKey(id);
        return code;
    }

    //根据品牌名称分页获取品牌列表
//    @Override
    public List<PmsBrand> getListPage(String keyword, Integer showStatus, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        PmsBrandExample example=new PmsBrandExample();
        example.setOrderByClause("sort desc");
        PmsBrandExample.Criteria criteria= example.createCriteria();
        if(!StrUtil.isEmpty(keyword)){
            criteria.andNameLike("%"+keyword+"%");
        }
        if(showStatus!=null){
            criteria.andShowStatusEqualTo(showStatus);
        }
        List<PmsBrand> pmsBrandList=pmsBrandMapper.selectByExample(example);

        return pmsBrandList;
    }

    //根据编号获取品牌信息
    public PmsBrand getById(Long id){
        PmsBrand pmsBrand= pmsBrandMapper.selectByPrimaryKey(id);
        return pmsBrand;
    }

    //批量删除品牌
    public int deleteByBatch(List<Long> ids){
        PmsBrandExample example=new PmsBrandExample();
        PmsBrandExample.Criteria criteria= example.createCriteria();
        criteria.andIdIn(ids);
        int code=pmsBrandMapper.deleteByExample(example);
        return code;

    }

    //批量更新品牌显示状态
//    @Override
    public Integer updateshowStatusByBatch(List<Long> ids, Integer showStatus) {
        PmsBrand pmsBrand=new PmsBrand();
        pmsBrand.setShowStatus(showStatus);
        PmsBrandExample example=new PmsBrandExample();
        PmsBrandExample.Criteria criteria=example.createCriteria();
        criteria.andIdIn(ids);
        Integer code=pmsBrandMapper.updateByExampleSelective(pmsBrand,example);

        return code;
    }

    //批量更新 品牌制造商状态
//    @Override
    public Integer updateFactoryStatusByBatch(Integer factoryStatus, List<Long> ids) {
        PmsBrand pmsBrand=new PmsBrand();
        pmsBrand.setFactoryStatus(factoryStatus);
        PmsBrandExample example=new PmsBrandExample();
        PmsBrandExample.Criteria criteria= example.createCriteria();
        criteria.andIdIn(ids);
        Integer code=pmsBrandMapper.updateByExampleSelective(pmsBrand,example);

        return code;
    }

}
